package thread.java20221230;

import java.util.Scanner;

/**
 * volatile 的使用
 */
public class Demo28 {
    static volatile int flag = 0;
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            System.out.println("t1 开始循环...");
            while (flag == 0){

            }
            System.out.println("t1 循环结束...");
        });
        t1.start();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入flag的值:");
        flag = scanner.nextInt();
    }
}
